﻿@model RBS.Core.Model.D_Order
@{
    ViewBag.Title = "订单";
    Layout = "~/Views/Shared/_Layout.cshtml"; 
}

<link href="~/Scripts/datepicker/skin/WdatePicker.css" rel="stylesheet" />
<script src="~/Scripts/datepicker/lang/zh-cn.js"></script>
<script src="~/Scripts/datepicker/WdatePicker.js"></script>
 
@using (Html.BeginForm("SetOrder", "Yd", FormMethod.Post, new { id = "OrderForm" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
    @Html.HiddenFor(model => model.H_Id) 
    @Html.HiddenFor(model => model.Id)  
    <div id="content">
        <div class="h1a">本地商户</div>  
         @{
            var hotel = new RBS.Core.BLL.Hotel.H_Hotels().GetModelByCache(Model.H_Id); 
              @Html.Partial("_HotelHead",hotel);
            } 
        <div id="mainContent1">
            <div class="tab-content destineorder">
                <dl>
                    <dt><b>*</b>预订吃饭日期</dt>
                    <dd>
                        @Html.TextBoxFor(model => model.ReserveDate, null, new { @class = "input small w120", onfocus = "WdatePicker({doubleCalendar:true,dateFmt:'yyyy年MM月dd日',minDate:'%y-%M-{%d}',vel:'d244_2'})", @readonly = "readonly" }) 
                        
                        <input id="d244_2" type="hidden" />
                        @Html.TextBoxFor(model => model.ReserveTime, null, new { @class = "input small w120", errormsg = "吃饭时间不能小于当前时间", nullmsg = "请选择时间", @readonly = "readonly"}) 
                        <div id="divObj"  > 
                            <div id="divObjtab" class="divObjtab">
                                @{
                                    foreach (var dictParent in new RBS.Core.BLL.SYS_DictInfo().GetModelList(" parentid = (select DictID from sys_dictinfo where dictcode ='dctime') "))
                                    { 
                                                                        <div class="res_sel_tit" >@dictParent.DictName</div>  
                                                                        <ul>   
                                                                        @foreach (var dict in new RBS.Core.BLL.SYS_DictInfo().GetModelList(" parentid =" + dictParent.DictID))
                                                                        { 
                                                                            string st1 = dict.DictName;
                                                                            DateTime dt1 = Convert.ToDateTime(st1);
                                                                            DateTime dt3 = DateTime.Now;
                                                                            if (DateTime.Compare(dt1, dt3) > 0)
                                                                            { 
                                                                                <li >@dict.DictName</li>
                                                                            }
                                                                            else
                                                                            { 
                                                                                <li  class="data-sel"  >@dict.DictName</li>
                                                                            }   
                                                                        }  
                                                                        </ul>    
                                    }
                                }    
                            </div> 
                  </div> 
                                     
                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>就餐人数</dt>
                    <dd>
                        @Html.TextBoxFor(model => model.DineNum, null, new { @class = "input normal w100", datatype = "n", value = "" })
                        <span class="Validform_checktip">*就餐人数</span>
                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>餐位情况</dt>
                    <dd class="ltable">  
                        @Html.RadioButton("Dinecondition", "大厅", new { @checked = "checked" })
                          <label for="Dinecondition">大厅</label>  
                        @Html.RadioButton("Dinecondition", "包间")
                         <label for="Dinecondition">包间</label>
                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>桌位</dt>
                    <dd> 
                        @Html.HiddenFor(model => model.DineTable)
                        @Html.Hidden("OldDineTable", null, new { value = @ViewBag.DineTable })
                        <script type="text/template" id="SeatTemplate">
                            <li id="li{{Id}}" name="{{Name}}">
                                <p>  
                                    <a href="@(RBS.Common.ConfigHelper.GetConfigString("hotelWeb")){{Picture}}"  title="{{Name}}" class="example-image-link" data-lightbox="example-{{Id}}" >
                                        <img src="@(RBS.Common.ConfigHelper.GetConfigString("hotelWeb")){{Picture}}" alt="{{Name}}" class="example-image" onerror="javascript:this.src='../Content/noPic.png';" /></a>
                                </p>
                                <h4>
                                <input type="radio" id="seat{{Id}}" name="seat" value="{{Id}}" datatype="seat" nullmsg="请选择座位！" errormsg="请选择座位" onclick="selectTable('{{Id}}', '{{Name}}')"  {{s}}    />{{Name}}</h4>
                            </li>
                        </script> 
                        <ul id="seatUl"></ul> 
                           <span class="Validform_checktip">*就餐人数</span>
                        <span id="selectTable" ></span>
                    </dd>
                </dl>

                <dl>
                    <dt><b>*</b>联系人</dt>
                    <dd>

                        @Html.TextBoxFor(model => model.ContactUser, null, new { @class = "input normal w100" })
                        <span class="Validform_checktip">*联系人</span>

                    </dd>
                </dl>
                <dl>
                    <dt><b>*</b>用户手机</dt>
                    <dd>

                        @Html.TextBoxFor(model => model.ContactMobile, null, new { @class = "input normal w100" })
                        <span class="Validform_checktip">*用户手机</span>

                    </dd>
                </dl>
                <dl>
                    <dt>订单备注</dt>
                    <dd> 
                        @Html.TextBoxFor(model => model.OrderRemark, null, new { @class = "input normal" })
                        <span class="Validform_checktip">*订单备注</span> 
                    </dd>
                </dl>
                <div class="destineorderbtn">
                    @Html.Hidden("SetOrder")
                    <input type="submit" id="BtnNextOrder" value="确认"  class="btn" />
                
                </div>
            </div>
        </div>

        <div id="sideContent">
        </div>
    </div>
     
    <script>
        $(function () {
            if ($(".ltable :radio[id='Dinecondition']:checked").val() != "undefined") {
                GetSeat($(".ltable :radio[id='Dinecondition']:checked").val());
            }
            $(".ltable :radio[id='Dinecondition']").each(function () {
                $(this).click(function () {
                    GetSeat(this.value);
                });
            });
        }); 
        $(function () {
            //绑定事件处理 
            $("#ReserveTime").click(function (e) {
                var reserveDate = $("#d244_2").val();
                if (reserveDate == "") {
                    $.dialog.alert("请先选择日期");
                    return false;
                }  
                if ($("#divObj").css("display") == "none") {
                    e.stopPropagation();
                    //设置弹出层位置 
                    var offset = $(e.target).offset();
                    //设置弹出层位置在点击的下面 
                    $("#divObj").css({ top: (offset.top + $(e.target).height() + 5) + "px", left: offset.left });
                    $("#divObj").show(); 
                    var mytime = reserveDate;
                    mytime = mytime.replace("-", "/");//替换字符，变成标准格式   
                    var d1 = new Date(Date.parse(mytime));
                    var today = new Date();
                    //alert(d1);
                    /*if (d1 > today) { 
                        $("#divObjtab ul li").removeClass("data-sel");
                        $("#divObjtab ul li").removeAttr("disabled");
                    }
                    else { 
                        $("#divObjtab ul li").addClass("data-sel");
                        $("#divObjtab ul li").attr("disabled", "disabled");
                    }*/
                /*    $("#divObjtab ul li").addClass("data-sel");
                    $("#divObjtab ul li").attr("disabled", "disabled");*/
                    $("#divObjtab ul li").each(function () {
                        
                        mytime = mytime.replace("-", "/") + " " + $(this).html();
                        d1 = new Date(Date.parse(mytime));
                       // alert(d1);
                        if (d1 > today) {
                            $("#divObjtab ul li").removeClass("data-sel");
                            $("#divObjtab ul li").removeAttr("disabled");
                        }  
                    });
                  
                }
                else {
                    $("#divObj").hide();
                }
            });
            //单击空白区域隐藏弹出层 
            $(document).click(function (event) { $("#divObj").hide(); });
            $("#divObjtab ul li").click(function (event) {
                $("#ReserveTime").val($(this).html());
            });
        });
     
        function selectTable(id, name) {  
            var a = $("#d244_2").val();
            var b = $("#ReserveTime").val();
            var c = a + " " + b; 
            $.get("@Url.Action("GetSeatStatus")?sid=" + id + "&time=" + c, function (result) {
              
                if (result.IsSuccess) {
                    $.dialog.alert("当前座位已有预定，请选择别的座位"); 
                    $('input[name=seat]:checked').attr('checked', false);
                    return false;
                } else {
                    $("#DineTable").val(id);
                    $("#selectTable").html("您选择的是" + name);
                } 
            }); 
        }
        function GetSeat(dineValue) {
            var url = "@Url.Action("GetSeat", "Store")?hid=" + @Model.H_Id +"&type=" + encodeURIComponent(dineValue);
            var dine = dineValue;
            $.ajax({
                url: url,
                type: 'Post',
                dataType: 'json',
                success: function (result) {
                    if (result == null)
                        return;
                    $("#seatUl").empty();
                    $.each(result.Data, function (index, row) {
                        var ss = "";
                        if (row.Id == $("#DineTable").val()) {
                            ss = "checked";
                        }
                        row.s = ss;

                        if (row.Picture == "") {
                            row.Picture = "Content/noPic.png";
                        }

                        var template = $('#SeatTemplate').html(); //获取模版的html 
                        var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                        $("#seatUl").append(bookData);
                    });
                }
            });
        } 
        $.extend($.Datatype, {
            "seat": function (gets, obj, curform, regxp) {
                var need = 1,
                    numselected = curform.find("input[name='" + obj.attr("name") + "']:checked").length;
                return numselected >= need ? true : false;
            }
        });


    </script>
 
        
}
 


